<?php
class Default_Model_DbTable_Menu extends Zend_Db_Table_Abstract {
	protected $_name = 'menu';
	public function addMenu($parent_id, $menu_name, $description, $img, $controller, $status) {
		$data = array (
				'PARENT_ID' => $parent_id,
				'MENU_NAME' => $menu_name,
				'MENU_DESCRIPTION' => $description,
				'IMG' => $img,
				'CONTROLLER' => $controller,
				'STATUS' => $status 
		);
		return $this->insert ( $data );
	}
	public function updatemenu($id, $parent_id, $menu_name, $description, $img, $controller, $status) {
		$data = array (
				'PARENT_ID' => $parent_id,
				'MENU_NAME' => $menu_name,
				'MENU_DESCRIPTION' => $description,
				'IMG' => $img,
				'CONTROLLER' => $controller,
				'STATUS' => $status 
		);
		return $this->update ( $data, "ID = $id" );
	}
	public function removemenu($id) {
		return $this->delete ( "ID = $id" );
	}
	public function getParentMenu($menu_id, $status) {
		return $this->fetchRow ( "ID = $menu_id And STATUS = $status" );
	}
	public function getMenuByParent($parent_menu_id, $status) {
		return $this->fetchAll ( "PARENT_ID = $parent_menu_id And STATUS = $status" );
	}
	public function getMenuHaveParent() {
		return $this->fetchAll ( "PARENT_ID != 0 AND STATUS = 1" )->toArray ();
	}
	public function getAllMenu() {
		return $this->fetchAll ()->toArray ();
	}
	public function getMenuByName($menu_name) {
		return $this->fetchRow ( "MENU_NAME = $menu_name" );
	}
	public function getMenuById($menu_id) {
		return $this->fetchRow ( "ID = $menu_id" );
	}
	public function getMenuByStatus($status) {
		// $SQL = $this->select()->from("menu",array("ID"))->where("STATUS =
		// $status and menu_NAME = 'dich vu'");
		// return $this->fetchAll($SQL)->toArray();
		return $this->fetchAll ( "STATUS = $status" );
	}
	public function updatestt($id) {
		$cat = $this->fetchRow ( "ID = $id" );
		if ($cat->STATUS == 1) {
			$this->update ( array (
					"STATUS" => "0" 
			), "ID = $id" );
		} else {
			$this->update ( array (
					"STATUS" => "1" 
			), "ID = $id" );
		}
	}
	
	// public function test() {
	// $select = $this->select ();
	// $select->where ( "ID= 1 OR menu_DESCRIPTION= 'sss'" );
	// $result = $this->fetchRow ( $select );
	// return $result;
	// }
}

